package com.ruoyi.web.controller.report;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.report.domain.CommunityPolicy;
import com.ruoyi.report.service.ICommunityPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 建议信息Controller
 * 
 * @author mac
 * @date 2023-02-11
 */
@RestController
@RequestMapping("/report/policy")
public class CommunityPolicyController extends BaseController
{
    @Autowired
    private ICommunityPolicyService communityPolicyService;

    /**
     * 查询建议信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CommunityPolicy communityPolicy)
    {
        startPage();
        List<CommunityPolicy> list = communityPolicyService.selectCommunityPolicyList(communityPolicy);
        return getDataTable(list);
    }

    /**
     * 导出建议信息列表
     */
    @PreAuthorize("@ss.hasPermi('report:policy:export')")
    @Log(title = "建议信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityPolicy communityPolicy)
    {
        List<CommunityPolicy> list = communityPolicyService.selectCommunityPolicyList(communityPolicy);
        ExcelUtil<CommunityPolicy> util = new ExcelUtil<CommunityPolicy>(CommunityPolicy.class);
        util.exportExcel(response, list, "建议信息数据");
    }

    /**
     * 获取建议信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('report:policy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(communityPolicyService.selectCommunityPolicyById(id));
    }

    /**
     * 新增建议信息
     */
    @PreAuthorize("@ss.hasPermi('report:policy:add')")
    @Log(title = "建议信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityPolicy communityPolicy)
    {
        return toAjax(communityPolicyService.insertCommunityPolicy(communityPolicy));
    }

    /**
     * 修改建议信息
     */
//    @PreAuthorize("@ss.hasPermi('report:policy:edit')")
    @Log(title = "建议信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityPolicy communityPolicy)
    {
        return toAjax(communityPolicyService.updateCommunityPolicy(communityPolicy));
    }

    /**
     * 删除建议信息
     */
//    @PreAuthorize("@ss.hasPermi('report:policy:remove')")
    @Log(title = "建议信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityPolicyService.deleteCommunityPolicyByIds(ids));
    }
}
